import { RosterInterface } from '@/api/interface/personnel/roster/roster';
import { BasicForm } from '@/components/ProForm/interface/index';
import { PublicInterface } from '@/interface/public';

/**
 * 工作经历
 */

export function useWorkExperienceForm(proTableBox: PublicInterface.ProTableValue) {
  let workExperienceForm = reactive<BasicForm<RosterInterface.ReqWorkInfoSave>>({
    form: {
      id: null,
      start: '',
      end: '',
      companyName: '',
      job: '',
      leaveReason: '',
      certifier: '',
      certifierPhone: '',
      remark: '',
      rosterId: null
    },
    title: '',
    minWidth: 660,
    labelWidth: [100, 120],
    visible: false,
    formAttrs: {
      labelWidth: '120px'
    },
    options: [
      {
        type: 'input',
        label: 'ID',
        prop: 'id',
        hide: true
      },
      {
        type: 'input',
        label: '主表id',
        prop: 'rosterId',
        hide: true
      },
      {
        type: 'date-picker',
        hide: false,
        prop: 'start',
        label: '开始日期',
        attrs: {
          type: 'date',
          valueFormat: BasicKey.DATE_FORMAT.YYYY_MM_DD
        },
        rules: [
          {
            required: true,
            message: '开始日期',
            trigger: 'change'
          }
        ]
      },
      {
        type: 'date-picker',
        hide: false,
        prop: 'end',
        label: '结束日期',
        attrs: {
          type: 'date',
          valueFormat: BasicKey.DATE_FORMAT.YYYY_MM_DD
        },
        rules: [
          {
            required: true,
            message: '结束日期',
            trigger: 'change'
          }
        ]
      },
      {
        type: 'input',
        hide: false,
        prop: 'companyName',
        label: '公司名称',
        rules: [
          {
            required: true,
            message: '公司名称',
            trigger: 'blur'
          }
        ]
      },
      {
        type: 'input',
        hide: false,
        prop: 'job',
        label: '担任职务',
        rules: [
          {
            required: true,
            message: '担任职务',
            trigger: 'blur'
          }
        ]
      },
      {
        type: 'input',
        hide: false,
        prop: 'leaveReason',
        label: '离开原因',
        rules: [
          {
            required: true,
            message: '离开原因',
            trigger: 'blur'
          }
        ]
      },

      {
        type: 'input',
        hide: false,
        prop: 'certifier',
        label: '证明人'
        // rules: [
        //   {
        //     required: true,
        //     message: "证明人",
        //     trigger: "blur"
        //   }
        // ]
      },
      {
        type: 'input',
        hide: false,
        prop: 'certifierPhone',
        label: '证明人手机号'
        // rules: [
        //   {
        //     required: true,
        //     message: "证明人手机号",
        //     trigger: "blur"
        //   }
        // ]
      },
      {
        type: 'input',
        hide: false,
        prop: 'remark',
        label: 'remark',
        attrs: {
          style: {
            width: '500px'
          }
        }
      }
    ]
  });

  /**
   * @description: 保存表单数据
   * @return {*}
   */
  const saveAddWorkExperienceForm = async form => {
    await workInfoSave(form);
    workExperienceForm.visible = false;
    elMessage();
    proTableBox.value?.getTableList();
  };

  return { workExperienceForm, saveAddWorkExperienceForm };
}
